﻿using System;
using System.ComponentModel;
using System.Data;
using ReflectionStudio.Core.Events;
using System.Windows;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
using System.Collections;
using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.IO;
using WPFExcelReport.Helpers;
using System.Windows.Input;

namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class THFBAB50
    {

        public THFBAB50()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABAUFM();
            DataContext = MV;
            InitializeComponent();
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            try
            {
               /* if (!FINISH.StartsWith("H"))
                    throw new Exception("请提供批号");*/
                dwData = TBMain.Clone().NewRow();
                dwData["ABAMANDANT"] = app.Mandant;
                dwData["ABAKDPARTIE"] = FINISH;
                SResult = TMV.QMU20(dwData);
                //纱支返回字段
                MergeData(SResult, false);
                IsEdit = false;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void PrintCommand(object sender, RoutedEventArgs e)
        {


            try
            {
                if (dwMaster == null)
                {
                    throw new Exception("请选择需要打印的生产单");
                }
                if (!System.IO.Directory.Exists("T:"))
                {
                    throw new Exception("请先映射T盘");
                }
                KRS = dwMaster["ABAAUFKRS"].ToString().Trim();
                LFD = dwMaster["ABAAUFLFD"].ToString().Trim();
                POS = dwMaster["ABAAUFPOS"].ToString().Trim();
                string order = KRS + "-" + Helper.GetSubRollNum(LFD) + "-" + Helper.GetSubRollNum(POS);  
                string DestFile = "T:\\YGRAB50GB20\\GB20" + order+".xls";
                if (!File.Exists(DestFile))
                {
                    throw new Exception(DestFile + "不存在");
                }
                System.Diagnostics.Process.Start("EXCEL.EXE", DestFile);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

            base.PrintCommand(sender, e);
        }
    }
}
